package com.highspeed.bdk.service.search;

import com.highspeed.bdk.service.physical.IBoardService;
import com.highspeed.bdk.service.physical.ICpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @program: bdk-service
 * @description:
 * @author: Chenjiabin
 * @create: 2018-04-22 20:29
 **/
@Service
public class SearchService {
    @Autowired
    private IBoardService boardService;
    @Autowired
    private ICpuService cpuService;

    public List<Map> search(String value) {
        List<Map> datas = new ArrayList<>(0);
        String boardSearchSql = "select board_id as no,board_type as type,board_name as name from board where board_name like ? or board_id like ?";
        List<Map> boards = boardService.getRepository().executeSqlQuery(boardSearchSql, new String[]{"%" + value + "%", "%" + value + "%"}, Map.class);
        if (boards != null) {
            datas.addAll(boards);
        }
        String cpuSearchSql = "select  cpu_id as no,cpu_type as type,'' as name  from cpu where cpu_name like ? or cpu_id like ?";
        List<Map> cpus = cpuService.getRepository().executeSqlQuery(cpuSearchSql, new String[]{"%" + value + "%", "%" + value + "%"}, Map.class);
        if (cpus != null) {
            datas.addAll(cpus);
        }
        return datas;
    }
}
